<!-- extend from base layout -->
{% extends "layout.html" %}

{% block extra_css %}

{% endblock %}

{% block content %}
    <div class="container">
    <ol class="breadcrumb">
        <li><a href="/">首页</a></li>
        <li class="active">我的团队</li>
    </ol>
    <!-- header -->
    <nav class="sub-header row container-fluid">

        <div class="btn-group pull-right" role="group" aria-label="...">
            {% if request.query_string == 'status_active=0' %}
            <a type="button" class="btn btn-default" href="{{ url_for('user.team') }}">全部团队</a>
            <a type="button" class="btn btn-default active">未激活</a>
            <a type="button" class="btn btn-default" href="{{ url_for('user.team', status_lock=1) }}">已锁定</a>
            {% elif request.query_string == 'status_lock=1' %}
            <a type="button" class="btn btn-default" href="{{ url_for('user.team') }}">全部团队</a>
            <a type="button" class="btn btn-default" href="{{ url_for('user.team', status_active=0) }}">未激活</a>
            <a type="button" class="btn btn-default active">已锁定</a>
            {% else %}
            <a type="button" class="btn btn-default active">全部团队</a>
            <a type="button" class="btn btn-default" href="{{ url_for('user.team', status_active=0) }}">未激活</a>
            <a type="button" class="btn btn-default" href="{{ url_for('user.team', status_lock=1) }}">已锁定</a>
            {% endif %}
        </div>
    </nav>

    <hr/>
    <!-- content -->
    <div class="table-responsive">
        {# <table class="table table-striped"> #}
        <table class="table table-hover">
            <thead>
            <tr>
                <th>用户ID</th>
                <th>用户名称</th>
                <th>用户等级</th>
                <th>激活状态</th>
                <th>锁定状态</th>
                <th>删除状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            {% for user_profile, user in pagination.items %}
            <tr class="text-muted">
                <td>{{ user_profile.user_id }}</td>
                <td>{{ user_profile.nickname }}</td>
                <td>{{ user_profile.type_level | type_level }}</td>
                <td>{{ user.status_active | status_active }}</td>
                <td>{{ user.status_lock | status_lock }}</td>
                <td>{{ user.status_delete | status_delete }}</td>
                <td>
                    {% if user.status_active == 0 %}
                    <a type="button" class="btn-sm btn-success" href="javascript:void(0);" onclick="user_active({{ user.id }});">
                        <span class="glyphicon glyphicon-star-empty"></span> 用户激活
                    </a>
                    {% else %}
{#                    <a type="button" class="btn-sm btn-success" href="javascript:void(0);" onclick="add_active({{ user.id }});">#}
                    <a type="button" class="btn-sm btn-success" href="{{ url_for('active.add', user_name=user_profile.nickname) }}">
                        <span class="glyphicon glyphicon-star-empty"></span> 赠送激活
                    </a>
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
        {# 翻页 #}
        {% from "macros.html" import render_pagination %}
        {{ render_pagination(pagination, 'user.team') }}
    </div>
    </div>
{% endblock %}

{% block extra_js %}
<script>
// 用户激活
function user_active(user_id) {
    //console.log($(form).serialize());

    if(confirm("为此用户激活账号，是否确认?"))
    {
        $.ajax({
            url: "{{ url_for('user.ajax_user_active') }}",
            type: 'POST',
            data: {user_id: user_id},
            dataType: 'json',
            success: function (result) {
                // console.log(result);
                if(result.hasOwnProperty('error')){
                    alert(result.error);
                }else {
                    alert(result.success);
                    document.location.reload();
                }
            }
        });
        return false;
    }
}

// 赠送激活
function add_active(user_id) {
    //console.log($(form).serialize());
    if(confirm("为此用户赠送激活码，是否确认?"))
    {
        $.ajax({
            url: "{{ url_for('user.ajax_add_active') }}",
            type: 'POST',
            data: {user_id: user_id},
            dataType: 'json',
            success: function (result) {
                // console.log(result);
                if(result.hasOwnProperty('error')){
                    alert(result.error);
                }else {
                    alert(result.success);
                    document.location.reload();
                }
            }
        });
        return false;
    }
}
</script>
{% endblock %}
